{% extends "base_generic.html" %}
{% load static %}

{% block content %}
<div class="container mt-4">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h1 class="mb-0"><i class="fas fa-sign-in-alt"></i> 登录</h1>
                </div>
                <div class="card-body">
                    {% if form.errors %}
                    <div class="alert alert-danger">用户名或密码错误，请重试。</div>
                    {% endif %}

                    {% if next %}
                        {% if user.is_authenticated %}
                        <div class="alert alert-warning">您的账户没有访问此页面的权限。</div>
                        {% else %}
                        <div class="alert alert-info">请登录以查看此页面。</div>
                        {% endif %}
                    {% endif %}

                    <form method="post" action="{% url 'login' %}">
                        {% csrf_token %}
                        <div class="mb-3">
                            <label for="id_username" class="form-label">用户名:</label>
                            <input type="text" name="username" class="form-control" id="id_username" required>
                        </div>
                        <div class="mb-3">
                            <label for="id_password" class="form-label">密码:</label>
                            <input type="password" name="password" class="form-control" id="id_password" required>
                        </div>
                        <div class="d-flex justify-content-between">
                            <button type="submit" class="btn btn-primary">登录</button>
                            <a href="{% url 'password_reset' %}" class="btn btn-link">忘记密码?</a>
                        </div>
                        <input type="hidden" name="next" value="{{ next }}">
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}